﻿using Catchbase.Web.ATest.Pages.Other;
using WatiN.Core;

namespace Catchbase.Web.ATest.Pages.Shared
{
    public class LogOnPartial
    {
        private readonly Browser _browser;
        private readonly GoogleAccount _googleAccount;
        private GoogleOpenId _googleOpenId;

        public LogOnPartial(Browser browser, GoogleAccount googleAccount, GoogleOpenId googleOpenId)
        {
            _googleOpenId = googleOpenId;
            _googleAccount = googleAccount;
            _browser = browser;
        }

        public Link LogonLink
        {
            get { return _browser.Link("logon"); }
        }

        public Link LogoffLink
        {
            get { return _browser.Link("logoff"); }
        }

        public void Logon(string username, string password)
        {
            if (!LogonLink.Exists)
                return;
            LogonLink.Click();
            if(_googleAccount.IsActive)
                _googleAccount.Logon(username, password);
            if(_googleOpenId.IsActive)
                _googleOpenId.Accept();
        }

        public void Logoff()
        {
            LogoffLink.Click();
        }
    }
}